define(["baseAsset", "webgl"], function(baseAsset, webgl) {
	return {
		create : function(path) {
			
			function processSource(txt, textStatus, jqXHR) {
				//compile it
				var gl 		= webgl.gl;
				var asset 	= jqXHR.asset;
				var type 	= asset.getPath().charAt(asset.getPath().lastIndexOf('/') + 1);
				asset.shader = gl.createShader(type === 'v' ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);
				gl.shaderSource(asset.shader, txt);
				gl.compileShader(asset.shader);
				
				//Check for error
				if (!gl.getShaderParameter(asset.shader, gl.COMPILE_STATUS)) {
				    alert("assetShader.js : " + gl.getShaderInfoLog(asset.shader));
					asset.unload();
				} 
				
				//Succeed
				else {
					asset.loadState = baseAsset.loadState.LOADED;
					jqXHR.callback(asset, jqXHR.params);
				}
			}
		
			var asset = baseAsset.create(path);
			
			asset.shader = null;
			
			asset.load = function(callback, params) {
				this.loadState 	= baseAsset.loadState.LOADING;
				var jqxhr 		= $.get(this.getPath(), processSource);
				jqxhr.asset 	= this;
				jqxhr.callback 	= callback;
				jqxhr.params 	= params;
			};
			
			asset.unload = function() {
				this.loadState = baseAsset.loadState.NOT_LOADED;
				if(!this.shader) return;
				webgl.gl.deleteShader(this.shader);
				this.shader = null;
			};
			
			return asset;
		} 
	};
});